// import com.alibaba.druid.DbType_ptr;
// import com.alibaba.druid.sql.ast.SQLExpr_ptr;
// import com.alibaba.druid.sql.ast.SQLName_ptr;
// import com.alibaba.druid.sql.ast.SQLObject;
// import com.alibaba.druid.sql.ast.SQLReplaceable;
// import com.alibaba.druid.sql.ast.SQLStatementImpl;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.Collections;
// import java.util.List;

#include "SQLBeginStatement.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../SQLName.h"

SQLBeginStatement::SQLBeginStatement()
{
}

SQLBeginStatement::SQLBeginStatement(DbType_ptr dbType)
    : SQLStatementImpl(dbType)
{
}

SQLName_ptr SQLBeginStatement::getTidbTxnMode()
{
  return tidbTxnMode;
}

void SQLBeginStatement::setTidbTxnMode(SQLName_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(SQLBeginStatement));
  }
  this->tidbTxnMode = x;
}

// @Override
void SQLBeginStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLBeginStatement)))
  {
    acceptChild(visitor, tidbTxnMode);
  }
  visitor->endVisit(SharedObject(SQLBeginStatement));
}

// @Override
BOOL_ptr SQLBeginStatement::replace(SQLExpr_ptr expr, SQLExpr_ptr target)
{
  if (this->tidbTxnMode == expr)
  {
    setTidbTxnMode(std::dynamic_pointer_cast<SQLName>(target));
    return BOOL::TRUE;
  }

  return BOOL::FALSE;
}

// @Override
SQLObject_list_ptr SQLBeginStatement::getChildren()
{
  SQLObject_list_ptr tmp = std::make_shared<std::list<SQLObject_ptr>>();
  tmp->push_back(tidbTxnMode);
  return tmp;
}
